@extends('admin.layouts.main')
@section('header')
    @parent
    <style>
        .quoteBox{
            padding: 5px;
            margin-top: 10px;
        }
    </style>
@endsection
@section('content')
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <span class="layui-btn layui-btn-sm layui-btn-primary">场数</span>
                <div class="layui-input-inline">
                    <input class="layui-input numberInput" type="number" min="0" value="30" placeholder="场数"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">胜率</span>
                <div class="layui-input-inline">
                    <input class="layui-input rateInput" type="search" value="70" placeholder="胜率"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">分数</span>
                <div class="layui-input-inline">
                    <input class="layui-input scoreInput" type="number" min="0" value="4" placeholder="分数"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">类型</span>
                <div class="layui-input-inline">
                    <select name="type" class="typeInput">
                        <option value="week">周</option>
                        <option value="month">月</option>
                        <option value="quarter" selected>三月</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="isGreat" class="greatInput">
                        <option value="1" selected>优秀</option>
                        <option value="0">垫底</option>
                    </select>
                </div>
                <div class="layui-btn-group">
                    <span class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm search-btn">
                        <i class="layui-icon">&#xe615;</i> 查询
                    </span>
                </div>
            </div>
        </form>

    </blockquote>
    <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
    {{--<div style="height: 100%">

    </div>--}}
    @verbatim
    <!-- 操作列 -->
    <script type="text/html" id="operTpl">
        <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="statistic">数据查看</a>
        <a class="layui-btn layui-btn-primary layui-btn-radius layui-btn-xs" lay-event="records">推荐记录</a>
    </script>
    <!-- 状态 -->
    <script type="text/html" id="statusTpl">
        <input type="checkbox" name="switch" lay-skin="switch" lay-filter="status"  lay-text="正常|禁用" {{ d.status ? 'checked' : '' }} data-id="{{ d.id }}" />
    </script>
    <script type="text/html" id="sexTpl">
        {{# if(d.sex == 1){ }}
        男
        {{# }else if(d.sex == 2){ }}
        女
        {{# }else{ }}
        保密
        {{# } }}
    </script>
    @endverbatim
@endsection

@section('footer')
    @parent
    <script type="text/javascript">
        layui.config({
            base:'{{ asset('xman/extends') }}/'
        }).extend({
            //treetable: 'treetable-lay/treetable'
        }).use([ 'laytpl','table','form'],function () {
            var laytpl = layui.laytpl,
                table = layui.table,
                form = layui.form;
            tableRender();
            function tableRender() {
                var number = $('.numberInput').val();
                var rate = $('.rateInput').val();
                var score = $('.scoreInput').val();
                var type = $('.typeInput').val();
                var isGreat = $('.greatInput').val();
                table.render({
                    elem:'#treeTable',
                    url: "{{ url('admin/lottery/pickUser') }}",
                    method: 'get',
                    where:{number:number,rate:rate,score:score,type:type,isGreat:isGreat},
                    page:{
                        layout:['limit', 'count', 'prev', 'page', 'next', 'skip'],
                        groups: 5
                    },
                    limit: 200,
                    limits: [100,200,300],
                    request:{
                        pageName: 'page',
                        limitName: 'pageSize'
                    },
                    response: {
                        statusName: 'status', //数据状态的字段名称，默认：code
                        statusCode: 200, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'totalCount', //数据总数的字段名称，默认：count
                        dataName: 'pages' //数据列表的字段名称，默认：data
                    },
                    cellMinWidth: 95,
                    height: "full",
                    id: "treeTable",
                    cols: [[
                        {field:'id',title:'ID',align:'center',width:80},
                        {field:'account',title:'账号',align:'center',width:100},
                        {field:'nickname',title:'昵称',align:'center',width:100},
                        {field:'email',title:'邮箱',align:'center',width:150},
                        {field:'sex',title:'性别',align:'center',templet:"#sexTpl",width:80},
                        {field:'status',title:'状态',align:'center',templet:'#statusTpl',width:100},
                        {field:'score',title:'积分',align:'center',width:150},
                        {title: '操作',templet:'#operTpl', width:300,fixed: "right", align: "left"}
                    ]]
                })
            }
            $('.search-btn').click(function () {
               tableRender();
            });
            //工具栏监听
            table.on("tool(treeTable)",function (obj) {
                var data = obj.data;
                var layEvent = obj.event;
                switch (layEvent){
                    case 'edit':
                        edit(data.id);
                        break;
                    case 'del':
                        changeStatus(data.id,'delete');
                        break;
                    case 'records':
                        openWindow('{{ url('admin/lottery/userRecord') }}?userId='+data.id,data.nickname+'__推荐记录')
                        break;
                    case 'recovery':
                        changeStatus(data.id,'recovery');
                        break;
                    case 'statistic':
                        openWindow('{{ url('admin/lottery/statistic') }}?id='+data.id,data.nickname+'__数据分析');
                }
            });
            //状态修改
            form.on("switch(status)",function (data) {
                var opt = 'forbidden';
                if(data.elem.checked){
                    opt = 'recovery';
                }
                goPost('{{ url('admin/user/status') }}',{id:$(this).attr('data-id'),opt:opt});
            });
            //编辑
            function edit(id) {
                openWindow('{{ url('admin/user/edit') }}?id='+id,'添加/编辑')
            }
            function changeStatus(id,opt) {
                goConfirm('{{ url('admin/user/status') }}',{id:id,opt:opt},'确定该操作?',0);
            }
        })
    </script>
@endsection